package com.ruoyi.mapper;
import com.ruoyi.domain.ErpPurchaseOrderPurchaseVO;
import com.ruoyi.domain.ErpPurchaseRequestManagement;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.ErpPurchaseOrderManagement;
import org.apache.ibatis.annotations.Select;

/**
 * 采购单管理Mapper接口
 * 
 * @author ruoyi
 * @date 2025-07-17
 */
@Mapper
public interface
ErpPurchaseOrderManagementMapper  extends BaseMapper<ErpPurchaseOrderManagement>
{
    /**
     * 查询采购单管理
     * 
     * @param id 采购单管理主键
     * @return 采购单管理
     */
    public ErpPurchaseOrderManagement selectErpPurchaseOrderManagementById(String id);

    /**
     * 查询采购单管理列表
     * 
     * @param erpPurchaseOrderManagement 采购单管理
     * @return 采购单管理集合
     */
    public List<ErpPurchaseOrderManagement> selectErpPurchaseOrderManagementList(ErpPurchaseOrderManagement erpPurchaseOrderManagement);

    /**
     * 新增采购单管理
     * 
     * @param erpPurchaseOrderManagement 采购单管理
     * @return 结果
     */
    public int insertErpPurchaseOrderManagement(ErpPurchaseOrderManagement erpPurchaseOrderManagement);

    /**
     * 修改采购单管理
     * 
     * @param erpPurchaseOrderManagement 采购单管理
     * @return 结果
     */
    public int updateErpPurchaseOrderManagement(ErpPurchaseOrderManagement erpPurchaseOrderManagement);

    /**
     * 删除采购单管理
     * 
     * @param id 采购单管理主键
     * @return 结果
     */
    public int deleteErpPurchaseOrderManagementById(String id);

    /**
     * 批量删除采购单管理
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteErpPurchaseOrderManagementByIds(String[] ids);

//    @Select({"<script>\n" +
//            "SELECT \n" +
//            "    a.*, b.*\n" +
//            "FROM \n" +
//            "    erp_purchase_order_management a\n" +
//            "JOIN \n" +
//            "    erp_supplier_management b ON a.supplier_id = b.id\n" +
//            "WHERE \n" +
//            "    a.purchase_request_id IN \n" +
//            "    <foreach collection=\"ids\" item=\"id\" open=\"(\" separator=\",\" close=\")\">\n" +
//            "        #{id}\n" +
//            "    </foreach>\n" +
//            "</script>"})
@Select({
        "SELECT \n" +
                "    a.*, \n" +
                "    b.*, \n" +
                "    c.* \n" +  // 明确包含erp_purchase_request_management表的字段
                "FROM \n" +
                "    erp_purchase_order_management a\n" +
                "INNER JOIN \n" +  // 使用INNER JOIN明确关联类型
                "    erp_supplier_management b ON a.supplier_id = b.id\n" +
                "INNER JOIN \n" +  // 与erp_purchase_request_management表的关联
                "    erp_purchase_request_management c ON a.purchase_request_id = c.id"
})
List<ErpPurchaseOrderPurchaseVO> selectpurchaseorder(@Param("ids") List<Integer> ids);

    @Select("SELECT *from  erp_purchase_order_management b join  order_item a  on a.order_id=b.id join erp_material c on a.material_id=c.id WHERE b.id=#{id}")

    List<ErpPurchaseOrderPurchaseVO> orderwuliaoId(@Param("id") int id);

    @Select("SELECT * FROM `erp_purchase_order_management` a join erp_supplier_management b ON a.supplier_id=b.id WHERE purchase_request_id IS NULL")
    List<ErpPurchaseOrderPurchaseVO> selectorder();


}
